<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>正则去除敏感词</title>
  <style>
      body {
          display: flex;
      }

      .input {
          width: 300px;
          height: 300px;
          border: 1px solid #000;
          padding: 10px;
      }

      .display {
          width: 300px;
          height: 300px;
          border: 1px solid #000;
          padding: 10px;
      }

      button {
          width: 100px;
          height: 50px;
      }
  </style>
</head>
<body>
<div class="input" contenteditable="true"></div>
<button>提交</button>
<div class="display"></div>
</body>
<script>
  let btn = document.getElementsByTagName('button')[0];
  let input = document.getElementsByClassName('input')[0];
  let display = document.getElementsByClassName('display')[0];

  let reg = /妈的|艹了|卧槽|去他妈|他奶奶的/g
  btn.onclick = function () {
    let str = input.innerText;
    str = str.replace(reg, '**');
    display.innerText = str;
  }
</script>
</html>